package com.hmall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.user.mapper.AddressMapper;
import com.hmall.user.mapper.UserMapper;
import com.hmall.user.pojo.Address;
import com.hmall.user.pojo.User;
import com.hmall.user.service.AddressService;
import com.hmall.user.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {
    @Autowired
    private AddressMapper addressMapper;

    /**
     * 根据id查询地址列表
     * @return 地址列表
     */
    @Override
    public List<Address> findAddressByUid() {
        Long userId = ThreadLocalUtil.getUserId();
        LambdaQueryWrapper<Address> wrapper = new LambdaQueryWrapper<>(Address.class);
        wrapper.eq(Address::getUserId,userId);
        List<Address> list = this.list(wrapper);
        return list;
    }

    @Override
    public Address getAddress(Long addrId) {
        LambdaQueryWrapper<Address> wrapper = new LambdaQueryWrapper<>(Address.class);
        wrapper.eq(Address::getId,addrId);
        Address address = this.getOne(wrapper);
        return address;
    }
}
